package com.qf.agro.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.agro.mapper.CropMapper;
import com.qf.agro.pojo.Crop;
import com.qf.agro.service.CropService;
import com.qf.agro.utils.JwtUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CropServiceImpl implements CropService {
    @Autowired
    private CropMapper cropMapper;
    @Override
    public Page<Crop> findPage(Integer pageNum, Integer pageSize, String name) {
        Page<Crop> page = new Page<>(pageNum,pageSize);
        LambdaQueryWrapper<Crop> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(name !=null, Crop::getName,name );
        page = cropMapper.selectPage(page,queryWrapper);
        return page;
    }

    @Override
    public void save(Crop crop) {
        cropMapper.insert(crop);
    }

    @Override
    public void update(Crop crop) {
        cropMapper.updateById(crop);
    }
    //@Override
    //public List<Crop> findAddFacilies() {
    //    LambdaQueryWrapper<Crop> queryWrapper = new LambdaQueryWrapper<>();
    //    queryWrapper.isNull(Crop::getFacilitiesName);
    //    List<Crop> crops = cropMapper.selectList(queryWrapper);
    //    for (Crop crop : crops) {
    //        LambdaQueryWrapper<Crop> wrapper = new LambdaQueryWrapper<>();
    //        wrapper.eq(Crop::getFacilitiesId,crop.getId());
    //    }
    //    return crops;
    //}
    @Override
    public void delete(Long id) {
        Crop crop = new Crop();
        crop.setStatus(1);
        LambdaQueryWrapper<Crop> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Crop::getId,id);
        cropMapper.delete(queryWrapper);
    }
}
